import { Component } from '@angular/core'
import {
  AlertController,
  NavController,
  App,
  ToastController
} from 'ionic-angular'
import { HttpServicesProvider } from '../../providers/http-services/http-services'
import { Storage } from '@ionic/storage'
import { LoginPage } from '../../pages/login/login'
import { ChangePasswordPage } from '../../pages/contact/change-password/change-password'
import { ChangeInformationPage } from '../../pages/contact/change-information/change-information'
@Component({
  selector: 'page-contact',
  templateUrl: 'contact.html'
})
export class ContactPage {
  constructor(
    public navCtrl: NavController,
    public alertCtrl: AlertController,
    private httpService: HttpServicesProvider,
    private local_storage: Storage,
    private app: App
  ) {}

  changePassword() {
    this.navCtrl.push(ChangePasswordPage)
  }
  information() {
    this.navCtrl.push(ChangeInformationPage)
  }

  showConfirm() {
    const confirm = this.alertCtrl.create({
      title: '是否退出',
      message: '退出后请重新登录',
      buttons: [
        {
          text: '否',
          handler: () => {}
        },
        {
          text: '是',
          handler: () => {
            this.httpService.requestDataLogoutGet((status, datas) => {
              if (status) {
                this.local_storage.clear()
                this.app.getRootNavs()[0].setRoot(
                  LoginPage,
                  {},
                  {
                    animate: true,
                    direction: 'back'
                  }
                )
              }
            })
          }
        }
      ]
    })
    confirm.present()
  }
}
